//
//  UIButton+Extension.swift
//  sinaBlog
//
//  Created by tianxiangyang on 15/12/16.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

import UIKit

extension UIButton{
 
    convenience init(imageName:String,backImageName:String){
    
        self.init()
        setImage((UIImage(named: imageName)), forState: UIControlState.Normal)
        setImage((UIImage(named:imageName + "_highlighted")), forState: UIControlState.Highlighted)
        
        setBackgroundImage((UIImage(named:backImageName)), forState: UIControlState.Normal)
        
        setBackgroundImage((UIImage(named:backImageName + "_highlighted")), forState: .Highlighted)
        
    
    }
//MARK:带有切片的button
    convenience init(title:String,imageName:String){
    
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        
        setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        
        var image = UIImage(named: imageName)
        
        let capW = image!.size.width * 0.5
        
        let capH = image!.size.height * 0.5
        
        image = image!.stretchableImageWithLeftCapWidth(Int(capW), topCapHeight: Int(capH))
        
        
        
        setBackgroundImage(image, forState: UIControlState.Normal)
        
        
    
    }
    

    convenience init(title:String,image_Name:String,titleColor:UIColor,fontSize:CGFloat){
    
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        
        setTitleColor(titleColor, forState: UIControlState.Normal)
        
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
        setImage(UIImage(named: image_Name), forState: UIControlState.Normal)
        
    
    }
    

}
